package com.tocici.controller;

import java.util.List;

import com.tocici.domain.vo.ArtistStatVo;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import com.tocici.domain.vo.ArtistVo;
import com.tocici.domain.bo.ArtistBo;
import com.tocici.service.IArtistService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 歌手
 *
 * @author zeratul
 * @date 2025-03-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/music/artist")
public class ArtistController extends BaseController {

    private final IArtistService artistService;

    /**
     * 查询歌手列表
     */
    @SaCheckPermission("music:artist:list")
    @GetMapping("/list")
    public TableDataInfo<ArtistVo> list(ArtistBo bo, PageQuery pageQuery) {
        return artistService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出歌手列表
     */
    @SaCheckPermission("music:artist:export")
    @Log(title = "歌手", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtistBo bo, HttpServletResponse response) {
        List<ArtistVo> list = artistService.queryList(bo);
        ExcelUtil.exportExcel(list, "歌手", ArtistVo.class, response);
    }

    /**
     * 获取歌手详细信息
     *
     * @param artistId 主键
     */
    @SaCheckPermission("music:artist:query")
    @GetMapping("/{artistId}")
    public R<ArtistVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long artistId) {
        return R.ok(artistService.queryById(artistId));
    }

    /**
     * 新增歌手
     */
    @SaCheckPermission("music:artist:add")
    @Log(title = "歌手", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArtistBo bo) {
        return toAjax(artistService.insertByBo(bo));
    }

    /**
     * 修改歌手
     */
    @SaCheckPermission("music:artist:edit")
    @Log(title = "歌手", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArtistBo bo) {
        return toAjax(artistService.updateByBo(bo));
    }

    /**
     * 删除歌手
     *
     * @param artistIds 主键串
     */
    @SaCheckPermission("music:artist:remove")
    @Log(title = "歌手", businessType = BusinessType.DELETE)
    @DeleteMapping("/{artistIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] artistIds) {
        return toAjax(artistService.deleteWithValidByIds(List.of(artistIds), true));
    }

    @GetMapping("/getHotArtist")
    public R<List<ArtistStatVo>> getHotArtist(){
        List<ArtistStatVo> list= artistService.getHotArtist();
        return R.ok(list);
    }
}
